package com.framework.core.tag;



import com.framework.core.constant.Globals;
import com.framework.web.sys.domain.Resource;

import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import java.io.IOException;
import java.util.List;
import java.util.Map;


/**
 * 类描述：菜单标签
 */
public class MenuTag extends TagSupport {
	private static final long serialVersionUID = 1L;
	protected String style="ace";//菜单样式
	protected List<Resource> parentFun;//一级菜单
	protected List<Resource> childFun;//二级菜单

	public int doEndTag() throws JspTagException {
		try {
			JspWriter out = this.pageContext.getOut();
			String menu = (String) this.pageContext.getSession().getAttribute(Globals.USER_LEFT_MENU_CACHE);
			if(menu!=null){
				out.print(menu);
			}else{
				menu = end().toString();
				this.pageContext.getSession().setAttribute(Globals.USER_LEFT_MENU_CACHE,menu);
				out.print(menu);

			}

		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_PAGE;
	}

	public StringBuffer end() {
		StringBuffer sb = new StringBuffer();
		if(style.equals("ace"))
		{
		Map<Integer, List<Resource>> menuFun = (Map<Integer, List<Resource>>) this.pageContext.getSession().getAttribute(Globals.USER_LEFT_MENU);
		sb.append(ListToMenu.getAceMultistageTree(menuFun));
		}
		return sb;
	}


	public void setStyle(String style) {
		this.style = style;
	}


	public void setParentFun(List<Resource> parentFun) {
		this.parentFun = parentFun;
	}

	public void setChildFun(List<Resource> childFun) {
		this.childFun = childFun;
	}

	public int doStartTag() throws JspTagException {
		return EVAL_PAGE;
	}




}
